/**
 * @file 工单-配置
 * @author yangjiangming <449654337@qq.com>
 * @date 2018-12-24 15:53:54
 */
layui.extend({

}).define(['$http', 'zmnUtils'], function (exports) {
    var $http = layui.$http;
    var opCommonUtils = layui.list_modify_common;
    var zmnUtils = layui.zmnUtils;

    window.zmnEnv = (function () {
        var host = location.host;
        if (/:/.test(host)) {
            return zmnEnum.ENV_TYPE.dev;
        } else if (/test-/.test(host)) {
            return zmnEnum.ENV_TYPE.test;
        } else if (/test2-/.test(host)) {
            return zmnEnum.ENV_TYPE.test2;
        } else if (/uat-/.test(host)) {
			return zmnEnum.ENV_TYPE.uat;
		} else if (/pre-/.test(host)) {
			return zmnEnum.ENV_TYPE.pre;
		} else {
            return zmnEnum.ENV_TYPE.prod;
        }
    })();

    function _calculateHostForCRM () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = '//dev-crm.xiujiadian.com:10613';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = '//test-crm.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = '//test2-crm.xiujiadian.com';
                break;
			case zmnEnum.ENV_TYPE.uat:
				host = '//uat-crm.xiujiadian.com';
				break;
			case zmnEnum.ENV_TYPE.pre:
				host = '//pre-crm.xiujiadian.com';
				break;
            case zmnEnum.ENV_TYPE.prod:
                host = '//crm.xiujiadian.com';
                break;
        }
        return host;
    }

    function _calculateHostForComplain () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = '//dev-admin.xiujiadian.com/bfm-complain';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = '//test-admin.xiujiadian.com/bfm-complain';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = '//test2-admin.xiujiadian.com/bfm-complain';
                break;
            case zmnEnum.ENV_TYPE.uat:
                host = '//uat-admin.xiujiadian.com/bfm-complain';
                break;
            case zmnEnum.ENV_TYPE.pre:
                host = '//pre-admin.xiujiadian.com/bfm-complain';
                break;
            case zmnEnum.ENV_TYPE.prod:
                host = '//admin.xiujiadian.com/bfm-complain';
                break;
        }
        return host;
    }

    function _calculateHostForAbnormal () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = '//dev-admin.xiujiadian.com/bfm-abnormal';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = '//test-admin.xiujiadian.com/bfm-abnormal';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = '//test2-admin.xiujiadian.com/bfm-abnormal';
                break;
            case zmnEnum.ENV_TYPE.uat:
                host = '//uat-admin.xiujiadian.com/bfm-abnormal';
                break;
            case zmnEnum.ENV_TYPE.pre:
                host = '//pre-admin.xiujiadian.com/bfm-abnormal';
                break;
            case zmnEnum.ENV_TYPE.prod:
                host = '//admin.xiujiadian.com/bfm-abnormal';
                break;
        }
        return host;
    }

    function _calculateHostForERP () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = 'http://dev-finance.xiujiadian.com:13013';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = 'http://test-finance.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = 'http://test2-finance.xiujiadian.com';
                break;
			case zmnEnum.ENV_TYPE.uat:
				host = 'http://uat-finance.xiujiadian.com';
				break;
			case zmnEnum.ENV_TYPE.pre:
				host = 'http://pre-finance.xiujiadian.com';
				break;
            case zmnEnum.ENV_TYPE.prod:
                host = 'https://finance.xiujiadian.com';
                break;
        }
        return host;
    }

    function _calculateHostForTrack () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = 'http://dev-track.xiujiadian.com:13013';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = 'http://test-track.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = 'http://test2-track.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.uat:
                host = 'http://uat-track.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.pre:
                host = 'http://pre-track.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.prod:
                host = 'https://track.xiujiadian.com';
                break;
        }
        return host;
    }

    function _calculateHostForAWS () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = 'http://dev-aws.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = 'http://test-aws.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = 'http://test2-aws.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.uat:
                host = 'http://uat-aws.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.pre:
                host = 'http://pre-aws.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.prod:
                host = 'https://aws.xiujiadian.com';
                break;
        }
        return host;
    }

    function _calculateHostForElephant () {
        var host;
        switch (window.zmnEnv) {
            case zmnEnum.ENV_TYPE.dev:
                host = 'http://dev-elephant.xiujiadian.com:15513';
                break;
            case zmnEnum.ENV_TYPE.test:
                host = 'http://test-elephant.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.test2:
                host = 'http://test2-elephant.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.uat:
                host = 'http://uat-elephant.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.pre:
                host = 'http://pre-elephant.xiujiadian.com';
                break;
            case zmnEnum.ENV_TYPE.prod:
                host = 'https://elephant.xiujiadian.com';
                break;
        }
        return host;
    }

    var operareIdEnum = {
        detail: 103
    };

    // var PLATFORM_ENUM = {
    //     YEYX: 20, // 言而有信
    //     ZMN: 10, // 啄木鸟
    //     YBWX: 30, // 一步维修
    //     CNHB: 40 // 川南环保
    // };

    /**
     * 投诉操作
     * @type {{special, editURL, permitID, name, host, listURL, id, url}}
     */
    var operateOfComplaint = (function () {
        // if (plat === platMark.YEYX) {
        //     return {
        //         id: 502,
        //         name: '投诉',
        //         url: '',
        //         permitID: '/track/yeyx/complain/list/add.action',
        //         editURL: '/track/yeyx/complain/edit.action',
        //         detailURL: '/track/yeyx/complain/list/detail.action',
        //         special: true,
        //         host: _calculateHostForCRM()
        //     };
        // }
		//
        // if (plat === platMark.CNHB) {
        //     return {
        //         id: 502,
        //         name: '投诉',
        //         url: '',
        //         permitID: '/track/cnhb/complain/list/add.action',
        //         editURL: '/track/cnhb/complain/edit.action',
        //         detailURL: '/track/cnhb/complain/list/detail.action',
        //         special: true,
        //         host: _calculateHostForCRM()
        //     };
        // }

        return {
            id: 502,
			name: '投诉',
			url: '',
			permitID: '/chs/complain/list/index.action?tabIndex=0&plat=' + plat,
			editURL: '/chs/complain/addEdit.action',
            detailURL: '/chs/complain/detail.action',
            special: true,
            host: _calculateHostForComplain()
        };
    }());

    var configuration = {
        operateListURL: '/work/operate/all/permission.action',
        operateObjectURL: '/work/operate/one/permission.action',
        operationList: [
            { id: 1, name: '下单', url: '' },
            { id: 2, name: '确认', url: '/work/modify/confirm.action' },
            { id: 3, name: '分单', url: '/work/modify/assign.action' },
            {
                id: 4,
                name: '派单',
                special: true,
                callback: function (params, successCallBack) {
                    // 查询是否有进行中的改派申请
                    $http.get('/work/redistribute/getWaitRedistributeApply.action', params).then(function (data) {
                       successCallBack(data);
                    }, function (msg) {
                        layer.msg(msg);
                    });
                }
            },
            {
                id: 17,
                name: '派单（新）',
                special: true,
                callback: function (params, successCallBack) {
                    // 查询是否有进行中的改派申请
                    $http.get('/work/redistribute/getWaitRedistributeApply.action', params).then(function (data) {
                        console.log(data);
                        console.log(params);
                        successCallBack(data);
                    }, function (msg) {
                        layer.msg(msg);
                    });
                }
            },
            { id: 6, name: '上门', url: '' },
            { id: 7, name: '完成', url: '/work/modify/complete.action' },
            { id: 8, name: '收单', url: '/work/modify/checkout.action' }, // 收单 - 子公司角色
            {
                id: 9,
                name: '算账',
                special: true,
                callback: function (params, successCallBack) {
                    layer.open({
                        title: '算账',
                        btn: ['确定','取消'],
                        content: '确认是要算账吗？',
                        yes: function (index, layero) {
                            layer.close(index);
                            // 调用接口
                            $http.get('/work/modify/save/account.action', params).then(function (data) {
                                successCallBack(data);
                            }, function (msg) {
                                layer.msg(msg);
                            });
                        },
                        btn2: function (index, layero) {
                            layer.close(index);
                        }
                    });
                }
            },

            { id: 11, name: '失败', url: '/work/modify/fail.action' },
            { id: 12, name: '弃单', url: '/work/modify/discard.action' },
            { id: 13, name: '回访', url: '/work/modify/reply/visit.action' },
            // { id: 14, name: '老总收单', url: '/work/modify/checkout.action' }, // 收单 - 子公司老总&总部角色
            { id: 15, name: '老总算账', url: '/work/modify/account.action' }, // 算账 - 子公司老总&总部角色
            { id: 16, name: '取消', url: '/work/modify/cancel.action' },
            { id: 23, name: '派单撤回', url: '/work/modify/distribute/back.action' },
            { id: 25, name: '转单', url: '/work/modify/turn.action'},
            { id: 26, name: '工单照片', url: '/work/modify/orderPhoto.action'},
            { id: 27, name: '挂起', url: '/work/modify/suspend.action' },// 挂起
            { id: 28, name: '服务完成', url: '/work/modify/serviceComplete.action' },

            { id: 101, name: '复制', url: '/work/modify/copy.action' },
            { id: 102, name: '返修', url: '/work/modify/rework.action' },
            { id: operareIdEnum.detail, name: '详情', url: '/work/modify/detail.action' },
            { id: 104, name: '备注', url: '/work/modify/remark.action' },
            { id: 105, name: '分单撤回', url: '/work/modify/assign/back.action' },
            { id: 106, name: '工程师备注', url: '' },
            { id: 107, name: '多工程师', url: '/work/modify/multimaster.action' },
            { id: 108, name: '测试单', url: '/work/modify/test.action' },
            { id: 109, name: '重复单', url: '/work/modify/duplicate.action' },
            { id: 110, name: '录音', url: '/work/modify/recording.action' },
            { id: 120, name: '多工程师分润', url: '/work/modify/mastersharing.action' },

            { id: 201, name: '修改', url: '/work/modify/update.action' },
            { id: 202, name: '改渠道', url: '/work/modify/channel.action' },
            { id: 203, name: '改贴花', url: '/work/modify/applique.action'},
            // { id: 204, name: '改状态', url: '/work/modify/status.action' },
            // { id: 205, name: '改定金', url: '/work/modify/price.action' },
            { id: 206, name: '改预付款', url: '/work/modify/channelprepayamount.action' }, // 子公司改渠道预收
            // { id: 207, name: '改渠道费', url: '/work/modify/channelamount.action' },

            { id: 209, name: '优惠', url: '/work/modify/discount.action' },
            // { id: 210, name: '七折优惠', url: '/work/modify/discount.action' },
            // { id: 211, name: '九折优惠', url: '/work/modify/discount.action' },
            { id: 214, name: '特殊优惠', url: '/work/modify/discount.action' },

            { id: 301, name: '服务项目', url: '/work/modify/serviceitem.action' },
            { id: 302, name: '核配件', url: '/work/modify/part.action' },
            { id: 303, name: '保修信息', url: '/work/modify/warranty.action' }, // 电子保单

            { id: 401, name: '配件报销', url: '/work/modify/part/reimburse.action' },
            { id: 402, name: '开发票', url: '/work/modify/invoice.action' },
            { id: 406, name: '发票反馈', url: '/work/modify/invoiceFeedBack.action' },
            { id: 404, name: '推送开票', url: '/work/modify/invoiceRemind.action' },
            { id: 403, name: '退款', url: '/work/modify/refund.action' },

            { id: 450, name: '特殊调整', url: '/work/modify/specialAdjustment.action' },

            { id: 501, name: '跟单', url: '/work/modify/track.action' },
            { id: 505, name: '跟单-新', url: '/work/modify/newtrack.action' },
			{ id: 708, name: '签到', url: '/work/modify/sign/in.action' },
            { id: 709, name: '语音记录', url: '/work/modify/callRecord.action' },
            { id: 712, name: '非标信息', url: '/work/modify/nonstandard.action' },
            { id: 713, name: '快递信息', url: '/work/modify/orderPost.action' },
            { id: 714, name: '新机配件', url: '/work/modify/newMachinePart.action' },
            { id: 715, name: '强制派单', url: '/work/modify/mandatory/distribute.action' },
            { id: 716, name: '退款凭证', url: '/work/modify/refundVoucher.action' },
            { id: 719, name: '一键提醒', url: '/work/modify/reminder.action' },
            { id: 720, name: '更改分配', url: '/work/modify/change/assignment.action' },
            { id: 32, name: '服务完成审核', url: '/work/modify/serviceCompleteReview.action' },
            { id: 800, name: '标记', url: '/work/modify/ordertag.action' },
            { id: 723, name: '赔偿单审核', url: '/work/modify/compensate/review.action' },
            { id: 724, name: '打款凭证', url: '/work/modify/remit/voucher.action' },
            { id: 725, name: '抽查', url: '/work/modify/order/check.action' },
            { id: 726, name: '临时小号', url: '/work/modify/tempXno.action' },
            { id: 111, name: '多次上门', url: '/work/modify/multiple/visit.action' },
            // { id: 721, name: '赔偿单', url: '/work/modify/compensate.action' },
            operateOfComplaint,
            {
                id: 503,
                name: '服务异常',
                url: '',
                permitID: '503',
                editURL: '/abnor/abnormal/edit.action',
                listURL: '/abnor/abnormal/list.action',
                special: true,
                host: _calculateHostForAbnormal()
            },
            {
                id: 504,
                name: '用户档案卡',
                url: '',
                host: _calculateHostForCRM()
            },
            // 跳转
            { id: 601, name: '厂商单旧件返厂', url: '' },
            {
                id: 721,
                name: '赔偿单',
                special: true,
                callback: function (params, successCallback) {
                    // 调用接口
                    $http.get('/work/modify/compensateCount.action', params).then(function (data) {
                        successCallback(data);
                    }, function (msg) {
                        layer.msg(msg);
                    });
                }
            },
        ],
        url: {
            homeURL: '/work/modify/detail.action',
            saveNormalURL: '/order/normal/save.action',
            saveReworkURL: '/order/normal/reworkSave.action',
            saveShoppingCartURL: '/order/normal/shoppingCart/save.action',
            saveNormalFromPurposeURL: '/order/normal/saveFromPurposeOrder.action',
            saveSimpleURL: '/order/normal/simpleSave.action',
            updateNormalURL: '/work/modify/normal/save.action',
            saveFactoryURL: '/order/factory/save.action',
            saveBatchFactoryURL: '/order/factory/batchSave.action',
            saveEntrustURL: '/order/entrust/save.action',
        },
        operareIdEnum: operareIdEnum,
        erpHost: _calculateHostForERP(),
        trackHost: _calculateHostForTrack(),
        elephantHost: _calculateHostForElephant(),
        awsHost: _calculateHostForAWS()
    };

    exports('oms_work_config', configuration);
});
